//
//  HBPayCoinCell.m
//  HeartBeat
//
//  Created by karong on 2023/9/14.
//

#import "HBPayCoinCell.h"
#import "HBPayCoinModel.h"
#import "UIView+WSDraw.h"

@interface HBPayCoinCell ()
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *coinLabel;
@property (weak, nonatomic) IBOutlet UILabel *percentLabel;
@property (weak, nonatomic) IBOutlet UIView *percentView;

@end

@implementation HBPayCoinCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.percentView setupRoundedCornersWithCutCorners:(UIRectCornerBottomRight) withRadii:CGSizeMake(5, 5)];
}
- (void)setDataWithObject:(HBPayCoinModel *)object select:(BOOL)select {
    self.percentView.hidden = NO;
    self.titleLabel.text = SF(WSLocalized(@"前%ld章"), (long)object.chapter_num);
    
    if (appConfig.languageType == 2) {
        self.percentLabel.text = SF(@"%ld%% off", (long)(100 - object.percent));
    }
    else {
        self.percentLabel.text = SF(@"%.1f折", (object.percent / 10.0f));
    }
    self.coinLabel.text = SF(WSLocalized(@"%ld書幣"), (long)object.discountedPrice);
    [self setSelectStatus:select];
}

- (void)setDataWithCoin:(NSInteger)coin select:(BOOL)select {
    self.percentView.hidden = YES;
    self.titleLabel.text = WSLocalized(@"本章節");
    self.coinLabel.text = SF(WSLocalized(@"%ld書幣"), (long)coin);
    [self setSelectStatus:select];
}

- (void)setSelectStatus:(BOOL)select {
    UIColor * bgColor = select?[UIColor colorFromHexRGB:@"FFFCE9"]:UIColor.clearColor;
    UIColor * borderColor = select?UIColor.font_yellow_FFCC00:[UIColor colorFromHexRGB:@"cecece"];
    CGFloat borderWidth = select?1.5:0.5;
    self.layer.borderColor = borderColor.CGColor;
    self.layer.borderWidth = borderWidth;
    self.backgroundColor = bgColor;
}

@end
